package kz.pro.server.dao;


import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;


import kz.pro.shared.entity.UserEntity;


@Repository("userDAO")
public class UserDAOImpl implements UserDAO{
	
	@Autowired
	private HibernateTemplate hibernateTemplate;
	
	

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	@Override
	public void save(UserEntity userEntity) {
		hibernateTemplate.save(userEntity);
	}

	@Override
	public void remove(UserEntity user) {
		hibernateTemplate.delete(user);
		
	}

	@Override
	public void update(UserEntity userEntity) {
		hibernateTemplate.update(userEntity);
		
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<UserEntity> listUsers() {
		String query = "from UserEntity";
		List<UserEntity> userList = hibernateTemplate.find(query);
		return userList;
	}

	@Override
	public UserEntity getUserById(BigDecimal userId) {
		UserEntity user = hibernateTemplate.get(UserEntity.class, userId);
		return user;
	}

	@Override
	public void hello() {
		System.out.println("Heelo asdsasdad");
	}

}

